/**
* 模版
**/ 

<template>
  <div class="addQ">
    <h3 style="text-align: center">添加填空试题</h3>
    <el-form ref="form"
             :model="form"
             label-width="80px">
      <el-form-item label="题干内容">
        <el-input type="textarea"
                  v-model="form.topic"></el-input>
      </el-form-item>
      <el-form-item label="选择题库">
        <el-select v-model="form.sub"
                   placeholder="请选择科目">
          <el-option v-for="subb in allSub"
                     :value="subb"
                     :key="subb"></el-option>
          <!-- <el-option label="数学"
                   value="数学"></el-option>
        <el-option label="英语"
                   value="英语"></el-option> -->
        </el-select>
        <el-select v-model="form.grade"
                   placeholder="请选择年级">
          <el-option v-for="gradee in allGrade"
                     :value="gradee"
                     :key="gradee"></el-option>
          <!-- <el-option label="二年级"
                   value="二年级"></el-option>
        <el-option label="三年级"
                   value="三年级"></el-option>
        <el-option label="四年级"
                   value="四年级"></el-option> -->
        </el-select>
      </el-form-item>
      <el-form-item label="选择难度">
        <el-radio v-model="form.nandu"
                  label="简单">简单</el-radio>
        <el-radio v-model="form.nandu"
                  label="普通">普通</el-radio>
        <el-radio v-model="form.nandu"
                  label="困难">困难</el-radio>

      </el-form-item>
      <el-form-item label="题目状态">
        <el-switch v-model="form.status"></el-switch>
      </el-form-item>
      <el-form-item label="题目答案">
        <el-input v-model="form.daan"
                  placeholder="请输入答案"></el-input>
      </el-form-item>

      <el-form-item label="题目解析">
        <el-input type="textarea"
                  v-model="form.analysis"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"
                   @click="submit">立即创建试题</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>


<script>
import { addOption, addQuestion } from '../../../api/questionMG'
import { findGrade, findSub } from '../../../api/questionMG'
// 导入组件
// import headerComponent from "./head.vue";
// 导出模块
export default {
  // 模块名字
  name: 'danxuan',
  // 模块数据
  data() {
    //数据
    return {
      form: {
        type: '4',
        topic: '',
        sub: '',
        grade: '',
        nandu: '3',
        status: false,
        daan: '',

        analysis: '',
      },
      allSub: [],
      allGrade: [],
    }
  },
  // 注册组件
  components: {
    // headerComponent
  },
  // 监听指定值，只有指定值变化，才会触发
  watch: {},
  // 里面的函数只有调用才会执行（实时计算）里面是定义的方法
  methods: {
    clean() {
      location.reload()
    },
    submit() {
      console.log(this.form)

      addQuestion(this.form).then((res) => {
        if (res.data.code == 200) {
          console.log(res.data.code)
          alert('添加成功')
        }
      })
    },
  },
  created() {
    findGrade().then((res) => {
      console.log(res)
      this.allGrade = res.data
    }),
      findSub().then((res) => {
        console.log(res)
        this.allSub = res.data
      })
  },
}
</script>
// scoped 样式只在本组件使用
<style scoped>
/**
 * 导入css样式组件
 * @import "../assets/css/components/index.css";
 */
</style>
